package com.lbx.config;

import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 * @author 吕兵星
 * @date 2020/10/26 16:41
 */
public class LoginHandlerInterceptor implements HandlerInterceptor {

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        HttpSession session = request.getSession();
        Object loginInfo = session.getAttribute("loginInfo");
        if (loginInfo!=""&&loginInfo!=null){
            return true;
        }
        request.setAttribute("msg","还没有登录,请先登录");
        request.getRequestDispatcher("/").forward(request,response);
        return false;
    }
}
